package com.zymail.controller;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zymail.bean.ZyChannel;
import com.zymail.bean.ZyGood;
import com.zymail.bean.ZyGoodDe;
import com.zymail.bean.ZyGoodImg;
import com.zymail.service.ZyChannelService;
import com.zymail.service.ZyGoodDeService;
import com.zymail.service.ZyGoodImgService;
import com.zymail.service.ZyGoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/util")
public class UtilController extends BaseController{

    @Autowired
    ZyChannelService channelService;

    @Autowired
    ZyGoodDeService goodDeService;

    @Autowired
    ZyGoodImgService imgService;

    /**
     * 得到首页的channel
     * @return  List<Zychannel>
     */
    @GetMapping("/mainChannel")
    public List<ZyChannel> get_main_channel(){
        QueryWrapper<ZyChannel> wrapper = new QueryWrapper<>();
        wrapper.eq("role", 1);  //1代表首页channel
        return channelService.list(wrapper);
    }

    /**
     * 通过类别id得到图片
     * @param deId  类别id
     * @return  图片类
     */
    @GetMapping("/getimgbydeid/{deId}")
    public ZyGoodImg getimgBydeId(@PathVariable("deId") Integer deId){
        ZyGoodDe de = goodDeService.getById(deId);

        QueryWrapper<ZyGoodImg> wrapper = new QueryWrapper<>();
        wrapper.eq("good_id", de.getGoodId());
        wrapper.eq("type", 1);
        return imgService.getOne(wrapper);
    }

}
